﻿using CommonDevelop.Operator;
using CommonEngine;
using System;

namespace CommonDevelop.DB
{
    public class BaseEn
    {
        public int Sort { get; set; }
        public string BusinessID { get; set; }
        public bool IsDelete { get; set; }
        /// <summary>
        /// 最近更新时间转Int
        /// </summary>
        public int LastModified { get; set; }
        public string ModifyUserId { get; set; }
        public string ModifyUserName { get; set; }

        public void Executor(string UserId = null)
        {
            var UI = OperatorProvider.Provider.Current();
            if (UI.IsEmpty())
            {
                if (UserId.IsEmpty())
                    return;
                else
                    UI = OperatorProvider.Provider.CheckUser(UserId);
            }

            if (!UI.IsEmpty())
            {
                this.ModifyUserId = UI.UserId ?? "None";
                this.ModifyUserName = UI.FullName ?? "";
                this.BusinessID = UI.BusinessID ?? "";
            }
        }

        public void Completion(string BusinessID)
        {
            this.LastModified = CommonOP.GetIntByDT(DateTime.Now);
            this.ModifyUserId = "None";
            this.ModifyUserName = "AI";
            this.BusinessID = BusinessID;
        }

        public void Modified(DateTime dt)
        {
            this.LastModified = CommonOP.GetIntByDT(dt);
            if (this.ModifyUserId.IsEmpty())
                this.Executor();
        }

        public DateTime Modified()
            => CommonOP.GetDTByInt(this.LastModified);
    }
}
